package tw.BBT.BasalBodyTemperature.Listeners.TabPageContents.Page_Profile;

import tw.BBT.BasalBodyTemperature.BasalBodyTemperature;
import tw.BBT.BasalBodyTemperature.R;
import tw.BBT.BasalBodyTemperature.Components.Common.*;
import android.app.AlertDialog;
import android.view.View;
import android.view.View.OnClickListener;

public class ProfileUName_Listener implements OnClickListener {

	BasalBodyTemperature BBT;
	
	public ProfileUName_Listener(BasalBodyTemperature BBT) {
		this.BBT = BBT;
	}
	
	/* Listener for ReNameDiagram: 
	 * (a) button(PopUp_TextPicker_Apply)
	 * (b) button(PopUp_TextPicker_Cancel)
	 */
	class ReUName_Listener implements View.OnClickListener {

		AlertDialog ReNameDia;
		PopUp_TextPicker ReNameDiaView;
		
		ReUName_Listener(PopUp_TextPicker ReNameDiaView,AlertDialog ReNameDia) {
			this.ReNameDia = ReNameDia;
			this.ReNameDiaView = ReNameDiaView;
		}
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			long id = v.getId();
			if(id == R.id.PopUp_TextPicker_Apply){
				BBT.ProfileUName.setText(ReNameDiaView.getTextPicker_TextInput());
				ReNameDia.cancel();
			}	else if(id == R.id.PopUp_TextPicker_Cancel){
				ReNameDia.cancel();
			}			
		}
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		// AlertDialog Instance
		final AlertDialog ReNameDia = new AlertDialog.Builder(BBT).create();

		// Create view for AlertDialog
		PopUp_TextPicker ReNameDiaView = new PopUp_TextPicker(BBT);
		
		// Definition things
		ReNameDiaView.setTextPicker_Message("Your Name: ");
		ReNameDiaView.setTextPicker_TextInput(BBT.ProfileUName.getText());
		
		// Set Listener for AlertDialog
		ReUName_Listener ReUName_L = new ReUName_Listener(ReNameDiaView, ReNameDia);
		ReNameDiaView.setListener(ReUName_L);
		
		// Show AlertDialog
		ReNameDia.setView(ReNameDiaView.getView());
		ReNameDia.show();
		
	}
}
